package com.joinway.framework.support.validation.validator;

import java.util.regex.Pattern;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import com.joinway.framework.support.validation.constraints.CellPhone;

public class CellPhoneValidator implements ConstraintValidator<CellPhone, String>{

	final static Pattern pattern = Pattern.compile("\\d{11}");
	
	@Override
	public void initialize(CellPhone constraintAnnotation) {
		
	}

	@Override
	public boolean isValid(String value, ConstraintValidatorContext context) {
		return pattern.matcher(value == null ? "" : value.trim()).matches();
	}

}
